const path = require('path')
const flash = require('connect-flash')
const bodyParser = require('body-parser')
const config = require('config-lite')(__dirname)

const mongoose = require('./controllers/mongooseConnect')

const index = require('./routes/index')

var pkg=require("./package");

const express = require('express')
const app = express()

//启动mongodb 并用mongoose链接
mongoose(config.mongodburl)

//设置模板目录
app.set('views',path.join(__dirname,'views'))

//设置模板引擎
app.set('view engine','ejs')

//设置静态文件目录
app.use(express.static(path.join(__dirname, 'public')))

//flash 中间件，用来显示通知
app.use(flash())

// parse application/json
//app.use(bodyParser.json())

//路由
app.use('/',index)
///console.log('app.use('/',index)')

//监听端口，启动程序
app.listen(config.webport,()=>{console.log(`${pkg.name} listening on port ${config.webport}`)})